package com.ruoyi.common.utils;


import java.util.List;
import java.util.function.Function;


public class DatabaseUtil {

	/**
	  * 分批入库
	  * @param list 入库list
	  * @param insertFun 入库方法
	  * @param interval list分割间隔
	  * @return 入库size
	  */
	 public static Integer splitInsert(List<?> list, Function<List<?>, Integer> insertFun,Integer interval) {
	  if(list==null||list.size()==0) {
	   return 0;
	  }
	  int listSize=list.size();
	  int count=0;
	  for(int i = 0;i<list.size();i+=interval){
	   if(i+interval>listSize){        //作用为toIndex最后没有100条数据则剩余几条newList中就装几条
	    interval=listSize-i;
	   }
	   List<?> newList = list.subList(i,i+interval);
	   //插入新纪录
	   Integer res = insertFun.apply(newList);
	   count+=res*interval;
	  }
	  return count;
	 }

}
